package com.alan.search.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * 响应信息主体
 *
 * @param <T>
 * @author xuye0422
 */
@ApiModel(value = "响应信息")
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Data
public class ResultVO<T> extends BaseResultVO {

    private static final long serialVersionUID = -3318766750422389431L;

    @ApiModelProperty(value = "数据")
    private T data;

    public static <T> ResultVO<T> ok() {
        return build(null, ResultVO.SUCCESS, DEFAULT_SUCCESS_MSG);
    }

    public static <T> ResultVO<T> ok(T data) {
        return build(data, ResultVO.SUCCESS, DEFAULT_SUCCESS_MSG);
    }

    public static <T> ResultVO<T> ok(T data, String msg) {
        return build(data, ResultVO.SUCCESS, msg);
    }

    public static <T> ResultVO<T> failed() {
        return build(null, ResultVO.FAIL, null);
    }

    public static <T> ResultVO<T> failed(String msg) {
        return build(null, ResultVO.FAIL, msg);
    }

    public static <T> ResultVO<T> failed(int code, String msg) {
        return build(null, code, msg);
    }

    public static <T> ResultVO<T> failed(T data) {
        return build(data, ResultVO.FAIL, null);
    }

    public static <T> ResultVO<T> failed(T data, String msg) {
        return build(data, ResultVO.FAIL, msg);
    }

    private static <T> ResultVO<T> build(T data, int code, String msg) {
        ResultVO<T> result = new ResultVO<>();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }


}
